/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.form;

import org.rails.extjs.Option;
import org.rails.extjs.javascript.Function;

public class Checkbox extends Field {

	public Checkbox() {
		super();
	}

	public Checkbox(Option configOptions) {
		super(configOptions);
	}

	public Checkbox(String name) {
		super(name);
	}

	public Checkbox(String name,String boxLabel,Object inputValue,Boolean checked) {
		super(name);
		setInputValue(inputValue);
		setBoxLabel(boxLabel);
		setChecked(checked);
	}
	
	@Override
	public Tag getAutoCreate(){
		Tag ac = new	Tag();
		ac.setType("checkbox");
		ac.setAutocomplete("off");
		return getOption("autoCreate") == null ? ac : (Tag)getOption("autoCreate");
	}
	
	public void setBoxLabel(String boxLabel){
		addOption("boxLabel", boxLabel);
	}
	
	public String getBoxLabel(String boxLabel){
		return getString("boxLabel", "");
	}
	
	public void setChecked(Boolean checked){
		addOption("checked", checked);
	}
	
	public Boolean isChecked(){
		return getBoolean("checked",false);
	}
	
	public void setFieldClass(String fieldClass){
		addOption("fieldClass", fieldClass);
	}
	
	public String getFieldClass(){
		return getString("fieldClass","");
	}
	
	public void setFocusClass(String focusClass){
		addOption("focusClass", focusClass);
	}
	
	public String getFocusClass(){
		return getString("focusClass", "");
	}
	
	public void setHandler(Function handler){
		addOption("handler", handler);
	}
	
	public Function getHandler(){
		return (Function)getOption("handler");
	}

	public void setInputValue(Object inputValue){
		addOption("inputValue", inputValue);
	}
	
	public Object getInputValue(){
		return getOption("inputValue");
	}
	
	@Override
	public String getScript() {
		script = new StringBuffer("");
		createItems();
		script.append("new Ext.form.Checkbox(");
		script.append(createOptions());
		script.append(")");
		return script.toString();
	}

}
